package com.chenfan.mcn.enums;

import com.chenfan.common.extension.dict.DictTranslator;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 线下佣金-结算状态-枚举常量
 * @author wulg
 * @date 2023/6/5
 */
@Getter
@AllArgsConstructor
public enum OfflineCommissionSettleStatusEnum implements DictTranslator<Integer, String> {

    /**
     * 待结算
     */
    UNSETTLED(0, "待结算"),

    /**
     * 结算中
     */
    APPROVAL(1, "结算中"),

    /**
     * 待回款
     */
    UN_PAYBACK(2, "待回款"),

    /**
     * 部分回款
     */
    PART_PAYBACK(3, "部分回款"),

    /**
     * 已回款
     */
    ALL_PAYBACK(4, "已回款"),

    ;

    private final Integer code;

    private final String statusName;


    public static String getStatusName(Integer code) {
        if(Objects.isNull(code)) {
            return null;
        }
        for (OfflineCommissionSettleStatusEnum status : OfflineCommissionSettleStatusEnum.values()) {
            if (status.code.equals(code)) {
                return status.statusName;
            }
        }
        return null;
    }

    /**
     * 是审批中
     * @param code
     * @return
     */
    public static boolean isApproval(Integer code) {
        return OfflineCommissionSettleStatusEnum.APPROVAL.getCode().equals(code);
    }

    /**
     * 是审批通过
     * @param code
     * @return
     */
    public static boolean isPassed(Integer code) {
        return OfflineCommissionSettleStatusEnum.UN_PAYBACK.getCode().equals(code);
    }

    /**
     * 是否全部回款
     * @param code
     * @return
     */
    public static boolean isAllPayback(Integer code) {
        return OfflineCommissionSettleStatusEnum.ALL_PAYBACK.getCode().equals(code);
    }

    /**
     * 是待结算
     * @param code
     * @return
     */
    public static boolean isUnsettled(Integer code) {
        return OfflineCommissionSettleStatusEnum.UNSETTLED.getCode().equals(code);
    }

    /** 根据状态码任意匹配
     * @param code
     * @param items
     * @return
     */
    public static boolean anyMatch(Integer code, OfflineCommissionSettleStatusEnum... items) {
        boolean match = false;
        if(code != null) {
            for(OfflineCommissionSettleStatusEnum item : items) {
                if(item.getCode() == code.intValue()) {
                    match = true;
                    break;
                }
            }
        }
        return match;
    }

    @Override
    public String translate(Integer code) {
        return getStatusName(code);
    }
}
